#include "EpilReferenceObject.h"
#include "EpilInterpreter.h"
#include "EpilInterpreterException.h"


EpilReferenceObject::EpilReferenceObject( EpilInterpreter * interpreter )
: EpilObject( interpreter )
, m_refCount( 1 )
{
}


EpilReferenceObject::~EpilReferenceObject()
{
}


void EpilReferenceObject::IncreaseRefCount()
{
	m_refCount++;
}


void EpilReferenceObject::DecreaseRefCount()
{
	m_refCount--;
	if( m_refCount == 0 )
	{
		this->GetInterpreter()->ReleaseObject( this );
		return;
	}
	if( m_refCount < 0 )
	{
		throw EpilInterpreterException( t("Reference count < 0 ?!") );
	}
}


bool EpilReferenceObject::operator==( const EpilObject & rhs ) const
{
	return this == &rhs;
}


EpilObject * EpilReferenceObject::CreateCopy()
{
	this->IncreaseRefCount();
	return this;
}


void EpilReferenceObject::ReleaseCopy()
{
	this->DecreaseRefCount();
}